﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Lottery.Herper;

using Lottery.MediaData.Core;

namespace Lottery.MediaData.UI {
    public partial class NewIndexForm : Form {
        public NewIndexForm() {
            InitializeComponent();

            this.SetDialogStyle();
        }

        private void buttonCancel_Click(object sender, EventArgs e) {
            DialogResult = DialogResult.Cancel;
        }

        public string QiShu { get { return textBoxIndex.Text; } }

        private void buttonOK_Click(object sender, EventArgs e) {
            var qiShu = textBoxIndex.Text;
            if (string.IsNullOrEmpty(qiShu)) {
                this.ShowInfo("没有输入期数");
                textBoxIndex.Focus();
                return;
            }

            //检查是否已经存在改
            if (DataHelper.IndexExists(qiShu)) {
                this.ShowInfo(string.Format("期数 {0} 已经存在", qiShu));
                textBoxIndex.Focus();
                return;
            }

            var info = string.Format("请确认是否新增期数 {0} ?", qiShu);
            if (this.ShowYesNoInfo(info) != DialogResult.Yes) {
                return;
            }

            DataHelper.AddIndex(qiShu);
            DialogResult = DialogResult.OK;
            Close();
        }
    }
}
